package boot.spring.util;

import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.template.MetaTemplate;

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * @author : hanmalu
 * @date : 2024/3/28 7:57
 * Description :
 */
public class PoiTlUtils {

    public static void main(String[] args)throws Exception {
        PoiTlUtils.renderDocx();
    }


    public static void renderDocx() throws Exception {
        Map<String,String> dataMap = new HashMap<>();
        dataMap.put("title","数据工程管理中心");
        dataMap.put("zcr","我的测试");
        dataMap.put("chry","王老师");
        dataMap.put("hynr","正文内容正文内容正文内容正文内容正文内容正文内容正文内容正文内容正文内容正文内容正文内容正文内容正文内容正文内容正文内容正文内容正文内容正文内容正文内容正文内容正文内容"+"\r\n"+"xxx");
        dataMap.put("jyr","张三、里斯");
        dataMap.put("ywshr","我的测试");
        dataMap.put("shr","我的测试");
        dataMap.put("dd","我的测试");
        dataMap.put("sj","2024年01月03日");

        XWPFTemplate template = XWPFTemplate.compile("D:/data/pdcajituan.docx");

        List<MetaTemplate> list = template.getElementTemplates();

                template.render(dataMap);
                String id= String.valueOf(System.currentTimeMillis());
                String path = "d:/data/"+id+".docx";
        template.writeAndClose(new FileOutputStream(path));

        WordUtils.word2Pdf(path,
                "D:/data/" + UUID.randomUUID().toString() + ".pdf");

    }

}
